package com.jxdinfo.hussar.example.common.dict.controller;

import com.jxdinfo.hussar.example.common.annotation.Log;
import com.jxdinfo.hussar.example.common.core.controller.BaseController;
import com.jxdinfo.hussar.example.common.core.domain.AjaxResult;
import com.jxdinfo.hussar.example.common.core.page.TableDataInfo;
import com.jxdinfo.hussar.example.common.utils.poi.ExcelUtil;
import com.jxdinfo.hussar.example.common.enums.BusinessType;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.jxdinfo.hussar.example.common.dict.domain.SysDictSingle;
import com.jxdinfo.hussar.example.common.dict.service.ISysDictSingleService;

/**
 * 字典字段Controller
 *
 * @author ruoyi
 * @date 2024-03-21
 */
@RestController
@RequestMapping("/Dict/SysDictSingle")
public class SysDictSingleController extends BaseController
{
    @Autowired
    private ISysDictSingleService sysDictSingleService;


    /**
     * 查询字典字段列表
     */
    @GetMapping("/list")
    public TableDataInfo list(SysDictSingle sysDictSingle)
    {
        startPage();
        List<SysDictSingle> list = sysDictSingleService.selectSysDictSingleList(sysDictSingle);
        return getDataTable(list);
    }

    /**
     * 导出字典字段列表
     */
    @Log(title = "字典字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDictSingle sysDictSingle)
    {
        List<SysDictSingle> list = sysDictSingleService.selectSysDictSingleList(sysDictSingle);
        ExcelUtil<SysDictSingle> util = new ExcelUtil<SysDictSingle>(SysDictSingle.class);
        util.exportExcel(response, list, "字典字段数据");
    }

    /**
     * 获取字典字段详细信息
     */
    @GetMapping(value = "/get/{dictId}")
    public AjaxResult getInfo(@PathVariable("dictId") Long dictId)
    {
        return AjaxResult.success(sysDictSingleService.selectSysDictSingleByDictId(dictId));
    }

    /**
     * 新增字典字段
     */
    @Log(title = "字典字段", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysDictSingle sysDictSingle)
    {
        return toAjax(sysDictSingleService.insertSysDictSingle(sysDictSingle));
    }

    /**
     * 修改字典字段
     */
    @Log(title = "字典字段", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysDictSingle sysDictSingle)
    {
        return toAjax(sysDictSingleService.updateSysDictSingle(sysDictSingle));
    }

    /**
     * 删除字典字段
     */
    @Log(title = "字典字段", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{dictIds}")
    public AjaxResult remove(@PathVariable Long[] dictIds)
    {
        return toAjax(sysDictSingleService.deleteSysDictSingleByDictIds(dictIds));
    }
}
